package com.sogeti.mentormatch.business
{	
	import mx.rpc.IResponder;
	import com.adobe.cairngorm.business.ServiceLocator;
	/* import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent; */
	
	/**
	 * The LoginDelegate is simply a level of abstraction that breaks our service calls
	 * or backend service declarations out from our business logic like our commands and events.
	 * 
	 * And as we all know Java guys love more levels of abstraction.
	 */
	public class LoginDelegate
	{
		private var responder : IResponder;
		private var service : Object;
		
		/**
		 * Inside the constructor we want to pass in the Responder.
		 * If the command is accessing a Delegate then it IS an RPC Command, meaning its going
		 * to access a backend service. Thus on construction we pass in the 'responder' 
		 * which simply means the piece of code we will hand back the response from the backend to.
		 * 
		 * The responder here is going to be the LoginCommand. Its always the command that constructs the 
		 * delegate.
		 */
		public function LoginDelegate( responder : IResponder )
		{		
			this.service = ServiceLocator.getInstance().getRemoteObject( "UserManager" );
			this.responder = responder;
		}
		
		/**
		 * The doLogin() method is the method which opens up the services class where we delcare our
		 * backend services (In this application they are all remote objects, but they could be
		 * webservices, HTTPRequests, Remote Objects, or DataManagedServices.
		 * 
		 * We want to pass into this method the loginName and password strings.
		 */
		public function doLogin(loginName:String, password:String) : void
		{			
			var call : Object = service.login(loginName,password);
			call.addResponder( responder );
		}
		
	
		
	}
}